﻿using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using LIB.Core;
using System.Data;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DanhMuc
{

    [OperationContract]
    public void DoWork()
    {
        return;
    }
    [OperationContract]
    public string Fs_BoMon()
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_BOMON_LKE();
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_BO_MON_NH(string id, string ten)
    {
        try
        {
            c_nhapdiem.P_MON_NH(id, ten);
            return Fs_BoMon();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_MON_XOA(string id)
    {
        try
        {
            c_nhapdiem.P_XOA(id);
            return Fs_BoMon();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    ///Doanh muc nha
    ///
    [OperationContract]
    public string Fs_NHA_LKE()
    {
        try
        {
            return LibTable.FormTableToJson(c_nhapdiem.Fdt_NHA_LKE());
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_NHA_NH(string b_id, string b_ten)
    {
        try
        {
            string id = c_nhapdiem.Fs_NHA_NH(b_id, b_ten);
            return LibTable.FormTableToJson(c_nhapdiem.Fdt_NHA_LKE()) + "@" + id;
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_NHA_XOA(string id)
    {
        try
        {
            c_nhapdiem.P_NHA_XOA(id);
            return LibTable.FormTableToJson(c_nhapdiem.Fdt_NHA_LKE());
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    ///Doanh muc phong
    ///
    [OperationContract]
    public string Fs_PHONG_LKE(string idnha)
    {
        try
        {
            return LibTable.FormTableToJson(c_nhapdiem.Fdt_PHONG_LKE(idnha));
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_PHONG_NH(string b_id, string id_nha, string b_ten, string b_giuong)
    {
        try
        {
            string id = c_nhapdiem.Fs_PHONG_NH(b_id, id_nha, b_ten, LibConvert.ToInt(b_giuong));
            return Fs_PHONG_LKE(id_nha) + "@" + id;
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_PHONG_XOA(string id, string id_nha)
    {
        try
        {
            c_nhapdiem.P_PHONG_XOA(id);
            return Fs_PHONG_LKE(id_nha);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    //Hiện DS ký tuc

    [OperationContract]
    public string Fs_KT_DK_LK(string idPhong)
    {
        try
        {
            return LibTable.FormTableToJson(c_nhapdiem.Fdt_SV_KT_LKE(idPhong));
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }

    [OperationContract]
    public string Fs_SINH_VIEN_TIM(string ma)
    {
        try
        {
            return LibTable.FormTableToJson(c_nhapdiem.Fdt_SV_TIM(ma));
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    //Đăng ký phòng
    [OperationContract]
    public string Fs_PH_DK_NH(string idPh, string b_ma_sv, object[] a_grid)
    {
        try
        {
            int dem = 0, vtri = 0;
            for (int i = 0; i < a_grid.Length; i++)
            {
                if (((object[])a_grid[i])[2].ToString() == "Đăng ký")
                {
                    dem++;
                    vtri = i;
                }
                if (dem > 1)
                {
                    throw new Exception("loi:Chỉ được chọn một vị trí cho sinh viên:loi");
                }
            }
            c_nhapdiem.P_PHONG_DK(((object[])a_grid[vtri])[0].ToString(), idPh, b_ma_sv);
            return Fs_KT_DK_LK(idPh);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + "loi";
        }
    }
    [OperationContract]
    public string Fs_PHONG_DK_XOA(string id, string idphong)
    {
        try
        {
            c_nhapdiem.P_PHONG_DK_XOA(id, idphong);
            return Fs_KT_DK_LK(idphong);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + "loi";
        }
    }
    [OperationContract]
    public string Fs_PHONG_DK_CT(string ma_sv)
    {
        try
        {
            return LibTable.FormTableToJson(c_nhapdiem.Fdt_DK_PHONG_CT(ma_sv));
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + "loi";
        }
    }
    ///Lấy giường chưa đăng ký
    ///
    [OperationContract]
    public string Fs_PHONG_CHUA_DK(string map)
    {
        try
        {
            return LibTable.FormTableToJson(LIB.Data.SqlData.GetData(map, "PDK_PHONG_CDK"));
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + "loi";
        }
    }
    //Hieenjk sinh viễn đã đăng ký để chọn xem chi tiết
    [OperationContract]
    public string Fs_PHONG_DA_DK(string masv)
    {
        try
        {
            return LibTable.FormTableToJson(LIB.Data.SqlData.GetData(masv, "PDK_PHONG_SV_DK"));
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + "loi";
        }
    }
    //Chuyển thông tin phòng ở
    [OperationContract]
    public string Fs_PHONG_CHUYEN(string idcu, string phongcu, string idmoi, string pmoi, string ngay_nh, string b_ma, string ndung)
    {
        try
        {
            string b_ngay = LibConvert.DateToNumber(ngay_nh);
            c_nhapdiem.P_PHONG_DK_CHUYEN(idcu, phongcu, idmoi, pmoi, LibConvert.ToInt(b_ngay), b_ma, ndung);
            return "loi:Chuyển thành công:loi";
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + "loi";
        }
    }
    #region Ngành đào tạo
    [OperationContract]
    public string Fs_NGANH_DT_NH(string id, string id_nganhhoc, string ten)
    {
        try
        {
            c_nhapdiem.P_NGANH_DT_NH(id, id_nganhhoc, ten);
            return Fs_NganhDT(id_nganhhoc);// Thêm vào JSON
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_NganhDT(string id_nganhhoc)
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_NGANHDT_NGANHHOC_LKE(id_nganhhoc);
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_NGANH_DT_XOA(string id, string id_nganh)
    {
        try
        {
            c_nhapdiem.P_NGANH_DT_XOA(id);
            return Fs_NganhDT(id_nganh);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion
    #region Môn học
    [OperationContract]
    public string Fs_MON_HOC_NH(string id, string id_nganh, string ten)
    {
        try
        {
            c_nhapdiem.P_MON_HOC_NH(id, id_nganh, ten);
            return Fs_MonHoc(id_nganh);// Thêm vào JSON
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_MonHoc(string id_nganh)
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_MONHOC_NGANH_LKE(id_nganh);
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_MON_HOC_XOA(string id, string id_nganh)
    {
        try
        {
            c_nhapdiem.P_MON_HOC_XOA(id);
            return Fs_MonHoc(id_nganh);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion
    #region Tôn giáo
    [OperationContract]
    public string Fs_TON_GIAO_NH(string id, string ten)
    {
        try
        {
            string id_tongiao = c_nhapdiem.P_TON_GIAO_NH(id, ten);
            return Fs_TonGiao() + "@" + id_tongiao;// Thêm vào JSON
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_TonGiao()
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_TON_GIAO_LKE();
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_TON_GIAO_XOA(string id)
    {
        try
        {
            c_nhapdiem.P_TON_GIAO_XOA(id);
            return Fs_TonGiao();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion

    #region ------- Tinh ---------
    [OperationContract]
    public string Fs_Tinh()
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_TINH_LKE();
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_TINH_NH(string id, string ten)
    {
        try
        {
            c_nhapdiem.P_TINH_NH(id, ten);
            return Fs_Tinh();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_TINH_XOA(string id)
    {
        try
        {
            c_nhapdiem.P_TINH_XOA(id);
            return Fs_Tinh();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }


    #endregion
    #region Dân tộc
    [OperationContract]
    public string Fs_DAN_TOC_NH(string id, string ten)
    {
        try
        {
            string id_dantoc = c_nhapdiem.P_DAN_TOC_NH(id, ten);
            return Fs_Dantoc() + "@" + id_dantoc;// Thêm vào JSON
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_Dantoc()
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_DAN_TOC_LKE();
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_DAN_TOC_XOA(string id)
    {
        try
        {
            c_nhapdiem.P_DAN_TOC_XOA(id);
            return Fs_Dantoc();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion

    #region Huyện
    [OperationContract]
    public string Fs_HUYEN_NH(string id, string ten, string id_tinh)
    {
        try
        {
            string id_huyen = c_nhapdiem.P_HUYEN_NH(id, ten, id_tinh);
            return Fs_Huyen(id_tinh) + "@" + id_huyen;// Thêm vào JSON
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_Huyen(string id_tinh)
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_HUYEN_TINH_LKE(id_tinh);
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_HUYEN_XOA(string id, string id_tinh)
    {
        try
        {
            c_nhapdiem.P_HUYEN_XOA(id);
            return Fs_Huyen(id_tinh);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion
    #region Công văn
    [OperationContract]
    public string Fs_LCV_NH(string id, string ten, string gc)
    {
        try
        {
            string id_lcv = c_nhapdiem.P_LCV_NH(id, ten, gc);
            return Fs_Lcv() + "@" + id_lcv;// Thêm vào JSON
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_Lcv()
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_LCV_LKE();
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_LCV_XOA(string id)
    {
        try
        {
            c_nhapdiem.P_LCV_XOA(id);
            return Fs_Lcv();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    //-------- Chủ đề công văn --------
    [OperationContract]
    public string Fs_CDCV_NH(string id, string ten, string gc)
    {
        try
        {
            string id_cdcv = c_nhapdiem.P_CDCV_NH(id, ten, gc);
            return Fs_Cdcv() + "@" + id_cdcv;// Thêm vào JSON
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_CDCV_XOA(string id)
    {
        try
        {
            c_nhapdiem.P_CDCV_XOA(id);
            return Fs_Cdcv();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_Cdcv()
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_CDCV_LKE();
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    //-------- Tình trạng --------
    [OperationContract]
    public string Fs_TINH_TRANG_NH(string id, string ten, string gc)
    {
        try
        {
            string id_tinhtrang = c_nhapdiem.P_TINH_TRANG_NH(id, ten, gc);
            return Fs_TinhTrang() + "@" + id_tinhtrang;// Thêm vào JSON
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_TINH_TRANG_XOA(string id)
    {
        try
        {
            c_nhapdiem.P_TINH_TRANG_XOA(id);
            return Fs_TinhTrang();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_TinhTrang()
    {
        try
        {
            DataTable b_dt = c_ht.Fdt_TINH_TRANG_LKE();
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    // ------------ Văn bản ----------------
    [OperationContract]
    public string Fs_VAN_BAN_LKE(string loaivb, string id_chude, string id_tt)
    {
        try
        {
            luu.ht_nsd _nsd = new luu.ht_nsd();
            string id_ph = _nsd.id_ph;
            if(string.IsNullOrEmpty(id_ph))
                throw new Exception("Không lấy được mã phòng");
            DataTable b_dt_vb=new DataTable();
            b_dt_vb= c_ht.Fdt_VAN_BAN_LKE(id_ph, loaivb, id_chude, id_tt);
            
            return LibTable.FormTableToJson(b_dt_vb);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_KT_VanBan()
    {
        try
        {
            DataTable b_dt_loaivb = c_ht.Fdt_LCV_LKE();
            DataTable b_dt_chu_de = c_ht.Fdt_CDCV_LKE();
            DataTable b_dt_tinhtrang = c_ht.Fdt_TINH_TRANG_LKE();

            return LibTable.FormTableToJson(b_dt_loaivb) + "@" +
                LibTable.FormTableToJson(b_dt_chu_de) + "@" + LibTable.FormTableToJson(b_dt_tinhtrang);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    //--Nhập tt van ban
    [OperationContract]
    public string Fs_VAN_BAN_NH(string id_vb, string loaivb, string id_chude, string id_tt, string so_vb,
            string ngaygui, string id_noi_gui, string noi_gui, string id_nguoi_gui, string nguoi_gui,
        string id_noinhan, string noi_nhan, string id_nguoi_nh, string nguoi_nhan, string trich_dan, string noi_dung, string file)
    {
        try
        {
            luu.ht_nsd _nsd = new luu.ht_nsd();
            string id_ph = _nsd.id_ph;
            if (string.IsNullOrEmpty(id_ph))
                throw new Exception("Không lấy được mã phòng");
            string int_ngaygui = LIB.Core.LibConvert.DateToNumber(ngaygui);
            string b_ngay_nh = LIB.Core.LibConvert.DateToNumber(DateTime.Now.ToShortDateString());

            object[] a_gtri = new object[] { id_vb, loaivb, id_chude, id_tt, so_vb, int_ngaygui, id_noi_gui,
            noi_gui, id_nguoi_gui, nguoi_gui, id_noinhan, noi_nhan, id_nguoi_nh, nguoi_nhan, trich_dan, noi_dung, file, b_ngay_nh, _nsd.user, _nsd.id_user};

            LIB.Data.SqlData.ExeCuteProcedure(a_gtri, "PVANBAN_NH");

            DataTable b_dt_vb = c_ht.Fdt_VAN_BAN_LKE(id_ph, loaivb, id_chude, id_tt);
            return LibTable.FormTableToJson(b_dt_vb);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_VAN_BAN_XOA(string id_vb, string loaivb, string id_chude, string id_tt)//-- Xóa
    {
        try
        {
            LIB.Data.SqlData.ExeCuteProcedure(id_vb, "PVANBAN_XOA");
            luu.ht_nsd _nsd = new luu.ht_nsd();
            string id_ph = _nsd.id_ph;
            if (string.IsNullOrEmpty(id_ph))
                throw new Exception("Không lấy được mã phòng");
            DataTable b_dt_vb = c_ht.Fdt_VAN_BAN_LKE(id_ph, loaivb, id_chude, id_tt);
            return LibTable.FormTableToJson(b_dt_vb);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    //Thông tin chi tiết văn bản
    [OperationContract]
    public string Fs_VANBAN_CT(string id_ct)
    {

        try
        {
            DataTable b_dt_ct = LIB.Data.SqlData.GetData(id_ct, "PVANBAN_CT");
            return LibTable.FormTableToJson(b_dt_ct);
        }
        catch (Exception e)
        {
            return "loi:" + e.Message + ":loi";
        }
    }
    #endregion

    #region Phòng ban

    [OperationContract]
    public string Fs_PHONG_BAN_LKE()
    {
        try
        {
            DataTable b_dt = new DataTable();
            b_dt = LIB.Data.SqlData.GetData("PPHONG_BAN_LKE");
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    //Tim gan dung
    [OperationContract]
    public string Fs_PHONG_BAN_TIM(string b_ten)
    {
        try
        {
            DataTable b_dt = new DataTable();
            b_dt = LIB.Data.SqlData.GetData(b_ten, "PPHONGBAN_TIM_TEN");
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_PHONG_BAN_NH(string id_phong, string ten)
    {
        try
        {
            object[] so_id = LIB.Data.SqlData.ExeCuteProcedure(new object[] { id_phong, ten }, "@id", "PPHONG_BAN_NH");
            return so_id[0].ToString() + "@" + Fs_PHONG_BAN_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_PHONG_BAN_XOA(string id_phong)
    {
        try
        {
            LIB.Data.SqlData.ExeCuteProcedure(id_phong, "PPHONG_BAN_XOA");
            return Fs_PHONG_BAN_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }

    //Duyệt văn ban
    [OperationContract]
    public string Fs_VANBAN_DUYET(string id_vb)
    {
        try
        {
            LIB.Data.SqlData.ExeCuteProcedure(new object[] { id_vb }, "PVAN_BAN_DUYET");
            return "loi:Đã duyệt xong:loi";
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }

    //Tim kiem
    [OperationContract]
    public string Fs_VANBAN_TIM(string loai, string b_loaivb, string b_cde, string b_tt)
    {
        try
        {
            luu.ht_nsd _nsd = new luu.ht_nsd();
            string b_phong = "";
            if (_nsd.id_ph == null) throw new Exception("Mất kết nối");
            b_phong = _nsd.id_ph;
            DataTable b_dt = new DataTable();
            string b_quyen = _nsd.Quyen;
            string a = string.Empty;
            if (b_quyen == "ADMIN" || b_quyen == "CV") a = "C"; else a = "K";
            b_dt=LIB.Data.SqlData.GetData(new object[] { loai, a, b_loaivb, b_cde, b_tt, b_phong, _nsd.id_ns }, "PVAN_BAN_TIM");
            if (b_dt.Rows.Count == 0) throw new Exception("Không có số liệu");
            return LibTable.FormTableToJson(b_dt) ;
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion

    #region Trình độ

    [OperationContract]
    public string Fs_TD_LKE()
    {
        try
        {
            DataTable b_dt = new DataTable();
            b_dt = LIB.Data.SqlData.GetData("PTRINHDO_LKE");
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }

    [OperationContract]
    public string Fs_TD_NH(string id_td, string ten)
    {
        try
        {
            object[] so_id = LIB.Data.SqlData.ExeCuteProcedure(new object[] { id_td, ten }, "@id", "PTRINHDO_NH");
            return so_id[0].ToString() + "@" + Fs_TD_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_TD_XOA(string id_td)
    {
        try
        {
            LIB.Data.SqlData.ExeCuteProcedure(id_td, "PTRINH_DO_XOA");
            return Fs_TD_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion
    #region Chức vụ

    [OperationContract]
    public string Fs_CV_LKE()
    {
        try
        {
            DataTable b_dt = new DataTable();
            b_dt = LIB.Data.SqlData.GetData("PCHUC_VU_LKE");
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }

    [OperationContract]
    public string Fs_CV_NH(string id_td, string ten)
    {
        try
        {
            object[] so_id = LIB.Data.SqlData.ExeCuteProcedure(new object[] { id_td, ten }, "@id", "PCHUC_VU_NH");
            return so_id[0].ToString() + "@" + Fs_CV_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_CV_XOA(string id_td)
    {
        try
        {
            LIB.Data.SqlData.ExeCuteProcedure(id_td, "PCHUC_VU_XOA");
            return Fs_CV_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion
    #region Chính sách

    [OperationContract]
    public string Fs_CS_LKE()
    {
        try
        {
            DataTable b_dt = new DataTable();
            b_dt = LIB.Data.SqlData.GetData("PCHINH_SACH_LKE");
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }

    [OperationContract]
    public string Fs_CS_NH(string id_td, string ten)
    {
        try
        {
            object[] so_id = LIB.Data.SqlData.ExeCuteProcedure(new object[] { id_td, ten }, "@id", "PCHINHSACH_NH");
            return so_id[0].ToString() + "@" + Fs_CS_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_CS_XOA(string id_td)
    {
        try
        {
            LIB.Data.SqlData.ExeCuteProcedure(id_td, "PCHINH_SACH_XOA");
            return Fs_CS_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion
    #region Hợp đồng

    [OperationContract]
    public string Fs_HD_LKE()
    {
        try
        {
            DataTable b_dt = new DataTable();
            b_dt = LIB.Data.SqlData.GetData("PHOPDONG_LKE");
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }

    [OperationContract]
    public string Fs_HD_NH(string id_td, string ten)
    {
        try
        {
            object[] so_id = LIB.Data.SqlData.ExeCuteProcedure(new object[] { id_td, ten }, "@id", "PHOPDONG_NH");
            return so_id[0].ToString() + "@" + Fs_HD_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_HD_XOA(string id_td)
    {
        try
        {
            LIB.Data.SqlData.ExeCuteProcedure(id_td, "PHOPDONG_XOA");
            return Fs_HD_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion

    #region CHọn danh sách sinh viên theo phòng ban
    [OperationContract]
    public string Fs_NHANSU_PHONG(string id_phong)
    {
        try
        {
            DataTable b_dt = LIB.Data.SqlData.GetData(id_phong, "PPHONG_BAN_XOA");
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    

    #endregion

    #region Loại điểm
    [OperationContract]
    public string Fs_LOAI_DIEM_LKE()
    {
        try
        {
            DataTable b_dt = new DataTable();
            b_dt = LIB.Data.SqlData.GetData("PLOAI_KTRA_LKE");
            return LibTable.FormTableToJson(b_dt);
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_LOAI_DIEM_NH(string b_id, string b_ten, string hso)
    {
        try
        {
            LIB.Data.SqlData.ExeCuteProcedure(new object[] { b_id, b_ten,hso}, "PLOAI_KTRA_NH");
            return Fs_LOAI_DIEM_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    [OperationContract]
    public string Fs_LOAI_DIEM_XOA(string b_soid)
    {
        try
        {
           LIB.Data.SqlData.ExeCuteProcedure( new object[] {b_soid}, "PLOAI_KTRA_XOA");
           return Fs_LOAI_DIEM_LKE();
        }
        catch (Exception ex)
        {
            return "loi:" + ex.Message + ":loi";
        }
    }
    #endregion
}
